<template>
  <div class="unqualified">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span style="line-height: 36px;">不合格品处理</span>
      </div>
      <s-table
        :table="table"
        ref="table"
        @http="tableWatch">
        <el-table-column
          fixed="right"
          align="center"
          slot="operation"
          class-name="operationMore"
          label="可用操作"
          width="150">
          <template slot-scope="s">
            <el-button type="info" size="mini" @click="dialogInputOpen(s.row)">入库</el-button>
            <el-button type="info" size="mini" @click="dialogOutputOpen(s.row)">出库</el-button>
            <el-button type="info"  size="mini" @click="tableExport(s.row)">导出</el-button>
          </template>
        </el-table-column>
        <el-row>
          <el-col :xs="24" :lg="{span: 4, offset: 0}">
            <el-form-item label="ASN编号" prop="asnbh">
              <el-input type="text"
                        class="input"
                        v-model="autoVue_table_asnbh"
                        placeholder="ASN编号" spellcheck="false" auto-capitalize="off" auto-complete="off"
                        auto-correct="off"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!--
        <el-form-item label="ASN编号" prop="asnbh">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_asnbh"
                    placeholder="ASN编号" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="创建时间" prop="cjsj">
          <el-date-picker
            v-model="autoVue_table_cjsj"
            type="daterange"
            placeholder="选择日期范围">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="PO编号" prop="dycgdbh">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_dycgdbh"
                    placeholder="关联PO编号" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="供应商" prop="gysid">
        <el-input type="text"
        class="input"
        v-model="autoVue_table_gysid"
        placeholder="供应商名称" spellcheck="false" auto-capitalize="off" auto-complete="off"
        auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="收货时间" prop="shsj">
          <el-date-picker
            v-model="autoVue_table_shsj"
            type="daterange"
            placeholder="选择日期范围">
          </el-date-picker>
        </el-form-item>
        -->
      </s-table>
    </el-card>
    <s-dialog :dialog="dialogInput" :close="dialogInputInit">
      <p slot="title">不合格入库</p>
      <s-table
        :pagination="false"
        :table="tableInput"
        ref="tableInput"
        :multiSelect="true"
        @http="tableWatch">
        <el-table-column
          fixed="right"
          align="center"
          slot="operation"
          class-name="operationMore"
          label="操作"
          width="80">
          <template slot-scope="s">
            <el-button type="info" size="mini" @click="dialogChooseOpen(s.row, s.$index)" v-if="s.row.sl != s.row.sjsl">选择</el-button>
            <div v-else>
              <el-button type="danger" icon="delete" size="mini" @click="tableConfirmDelete(s.$index, s.row)" v-if="typeof s.row.lock !== 'undefined'"></el-button>
              <el-button type="success" size="mini" @click="dialogChooseOpen(s.row, s.$index)" icon="edit" v-else></el-button>
            </div>
          </template>
        </el-table-column>
        <el-form-item slot="multiSelect" label="多选操作" prop="multiSelect" v-if="tableInput.multiSelect">
          <el-row>
            <el-col :span="8">
              <el-button size="small" type="info" @click="dialogOperationOpen('tableInput')">操作人员</el-button>
            </el-col>
          </el-row>
        </el-form-item>
      </s-table>
      <el-button slot="footer" type="info" @click="dialogInputSave">确认上架</el-button>
    </s-dialog>
    <s-dialog :dialog="dialogChoose" :close="dialogChooseInit">
      <p slot="title">选择库位</p>
      <s-form :form="formDialogChoose" ref="formDialogChoose">
        <el-row>
          <el-col :xs="24" :lg="{span: 7, offset: 0}" class="">
            <el-form-item label="托盘码">
              <el-input
                type="text"
                disabled
                v-model="dialogChoose.row.lpn"
                placeholder="托盘码"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 7, offset: 1}" class="">
            <el-form-item label="货品编号">
              <el-input
                type="text"
                disabled
                v-model="dialogChoose.row.show_bh"
                placeholder="货品编号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 7, offset: 1}" class="">
            <el-form-item label="货品名称">
              <el-input
                type="text"
                disabled
                v-model="dialogChoose.row.show_mc"
                placeholder="货品名称"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: 7, offset: 0}" class="">
            <el-form-item label="收货数量">
              <el-input
                type="text"
                disabled
                v-model="dialogChoose.row.sl"
                placeholder="收货数量"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 7, offset: 1}" class="">
            <el-form-item label="生产日期">
              <el-input
                type="text"
                disabled
                v-model="dialogChoose.row.show_scrq"
                placeholder="生产日期"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 7, offset: 1}" class="">
            <el-form-item label="批次号">
              <el-input
                type="text"
                disabled
                v-model="dialogChoose.row.show_hppc"
                placeholder="批次号"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <!--
          <el-col :xs="24" :lg="{span: 7, offset: 0}" class="">
            <el-form-item prop="kwid" label="上架库位">
              <el-select v-model="formDialogChoose.kwid"
                         filterable
                         remote
                         placeholder="请选择上架库位"
                         @change="dialogChangeKwmc"
                         :remote-method="dialogRemoteKwmc">
                <el-option
                  v-for="item in dialogChoose.wmsfailedlibrary"
                  :key="item.id"
                  :label="item.mc"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          -->
          <el-col :xs="24" :lg="{span: 7, offset: 0}" class="">
            <el-form-item prop="kwid" label="上架库位">
              <el-select v-model="formDialogChoose.kwid"
                         filterable
                         remote
                         placeholder="请选择上架库位"
                         @change="dialogChangeKwmc">
                <el-option
                  v-for="item in dialogChoose.wmsfailedlibrary"
                  :key="item.id"
                  :label="item.mc"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 7, offset: 1}" class="">
            <el-form-item prop="sjsl" label="上架数量">
              <el-input-number
                v-model="formDialogChoose.sjsl"
                :min="1"
                :max="parseInt(dialogChoose.row.sl)"
                placeholder="上架数量"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 7, offset: 1}" class="">
            <el-form-item prop="czr" label="操作人员">
              <el-input
                type="text"
                v-model="formDialogChoose.czr"
                placeholder="操作人员"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </s-form>
      <el-button slot="footer" type="success" @click="dialogChooseSave" v-if="dialogChoose.row.sl != formDialogChoose.sjsl">保存</el-button>
      <el-button slot="footer" type="info" @click="dialogChooseSave" v-else>确认</el-button>
    </s-dialog>
    <s-dialog :dialog="dialogOperation" :close="dialogOperationInit">
      <p slot="title">生成操作人员</p>
      <s-form :form="formDialogOperation" ref="formDialogOperation">
        <el-row>
          <el-col :xs="24" :lg="{span: 23, offset: 0}">
            <el-form-item prop="mc" label="操作人员">
              <el-input
                type="text"
                v-model="formDialogOperation.mc"
                placeholder="操作人员"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </s-form>
      <el-button slot="footer" @click="dialogOperationSave">保存</el-button>
    </s-dialog>
    <s-dialog :dialog="dialogOutput" :close="dialogOutputInit">
      <p slot="title">不合格出库</p>
      <s-table
        :multiSelect="true"
        :pagination="false"
        :table="tableOutput"
        ref="tableOutput"
        @http="tableWatch">
        <el-table-column
          fixed="right"
          align="center"
          slot="operation"
          class-name="operationMore"
          label="操作"
          width="80">
          <template slot-scope="s">
            <el-button type="info" size="mini" @click="dialogChooseOutOpen(s.row, s.$index)" v-if="s.row.sl != s.row.sjsl">选择</el-button>
            <div v-else>
              <el-button type="danger" icon="delete" size="mini" @click="tableConfirmDelete(s.$index, s.row)" v-if="typeof s.row.lock !== 'undefined'"></el-button>
              <el-button type="success" size="mini" @click="dialogChooseOutOpen(s.row, s.$index)" icon="edit" v-else></el-button>
            </div>
          </template>
        </el-table-column>
        <el-form-item slot="multiSelect" label="多选操作" prop="multiSelect" v-if="tableOutput.multiSelect">
          <el-row>
            <el-col :span="8">
              <el-button size="small" type="info" @click="dialogOperationOutOpen('tableOutput')">操作人员</el-button>
            </el-col>
          </el-row>
        </el-form-item>
      </s-table>
      <el-button slot="footer" type="info" @click="dialogOutputSave">确认出库</el-button>
    </s-dialog>
    <s-dialog :dialog="dialogChooseOut" :close="dialogChooseOutInit">
      <p slot="title">选择库位</p>
      <s-form :form="formDialogChooseOut" ref="formDialogChooseOut">
        <el-row>
          <el-col :xs="24" :lg="{span: 7, offset: 0}" class="">
            <el-form-item label="托盘码">
              <el-input
                type="text"
                disabled
                v-model="dialogChooseOut.row.lpn"
                placeholder="托盘码"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 7, offset: 1}" class="">
            <el-form-item label="货品编号">
              <el-input
                type="text"
                disabled
                v-model="dialogChooseOut.row.show_bh"
                placeholder="货品编号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 7, offset: 1}" class="">
            <el-form-item label="货品名称">
              <el-input
                type="text"
                disabled
                v-model="dialogChooseOut.row.show_mc"
                placeholder="货品名称"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: 7, offset: 0}" class="">
            <el-form-item label="收货数量">
              <el-input
                type="text"
                disabled
                v-model="dialogChooseOut.row.sl"
                placeholder="收货数量"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 7, offset: 1}" class="">
            <el-form-item label="生产日期">
              <el-input
                type="text"
                disabled
                v-model="dialogChooseOut.row.show_scrq"
                placeholder="生产日期"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 7, offset: 1}" class="">
            <el-form-item label="批次号">
              <el-input
                type="text"
                disabled
                v-model="dialogChooseOut.row.show_hppc"
                placeholder="批次号"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: 7, offset: 0}" class="">
            <el-form-item prop="shkwmc" label="收货库位">
              <el-input
                type="text"
                disabled
                v-model="dialogChooseOut.row.shkwmc"
                placeholder="收货库位"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 7, offset: 1}" class="">
            <el-form-item prop="sjsl" label="出库数量">
              <el-input-number
                v-model="formDialogChooseOut.sjsl"
                :min="1"
                :max="parseInt(dialogChooseOut.row.sl)"
                placeholder="出库数量"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 7, offset: 1}" class="">
            <el-form-item prop="czr" label="操作人员">
              <el-input
                type="text"
                v-model="formDialogChooseOut.czr"
                placeholder="操作人员"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </s-form>
      <!--<el-button slot="footer" type="success" @click="dialogChooseOutSave" v-if="dialogChooseOut.row.sl != formDialogChooseOut.sjsl">保存</el-button>-->
      <el-button slot="footer" type="success" @click="dialogChooseOutSave">保存</el-button>
      <!--<el-button slot="footer" type="info" @click="dialogChooseOutSave" v-else>确认</el-button>-->
    </s-dialog>
    <s-dialog :dialog="dialogOperationOut" :close="dialogOperationOutInit">
      <p slot="title">生成操作人员</p>
      <s-form :form="formDialogOperationOut" ref="formDialogOperationOut">
        <el-row>
          <el-col :xs="24" :lg="{span: 23, offset: 0}">
            <el-form-item prop="mc" label="操作人员">
              <el-input
                type="text"
                v-model="formDialogOperationOut.mc"
                placeholder="操作人员"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </s-form>
      <el-button slot="footer" @click="dialogOperationOutSave">保存</el-button>
    </s-dialog>
  </div>
</template>

<script>
  import {AutoVue, AutoPromise} from '~/plugins/Tools';

  function __formChoose () {
    return {
      kwid: { value: '', rule: [ 'vNull__change' ], cRemarks: '' },
      sjsl: { value: 1, rule: ['vNull', 'vNumber'], cRemarks: '' },
      czr: { value: '', rule: ['vNull'], cRemarks: '' },
    };
  }
  function __formChooseOut () {
    return {
      sjsl: { value: 1, rule: ['vNull', 'vNumber'], cRemarks: '' },
      czr: { value: '', rule: ['vNull'], cRemarks: '' },
    };
  }
  function __formDialogOperation () {
    return {
      mc: { value: '', rule: [ 'vNull' ] },
    };
  }
  function __formDialogOperationOut () {
    return {
      mc: { value: '', rule: [ 'vNull' ] },
    };
  }
  export default AutoVue({
    name: 'inOperation_shangjia-FEcarWms',
    head: {
      'title': '不合格品处理',
      'meta': [
        { 'hid': 'description', 'name': 'description', 'content': '乐速科技平台 不合格品处理 查看不合格品处理信息' },
      ],
    },
    data: {
      table: {
        column: [ { label: '仓库',
          prop: 'ckmc',
          minWidth: '0px',
          cRemarks: '',
          search: false },
        { label: '货主',
          prop: 'hzmc',
          minWidth: '0px',
          cRemarks: '',
          search: false },
        { label: '供应商名称',
          prop: 'gysmc',
          minWidth: '0px',
          cRemarks: '',
          search: false },
        { label: 'ASN编号',
          prop: 'asnbh',
          minWidth: '0px',
          cRemarks: '',
          search: true },
        { label: 'PO编号',
          prop: 'dycgdbh',
          minWidth: '0px',
          cRemarks: '',
          search: true },
        { label: '质检单号',
          prop: 'zjdh',
          minWidth: '0px',
          cRemarks: '',
          search: false },
        { label: 'ASN类型',
          prop: 'show_asnlx',
          minWidth: '0px',
          cRemarks: '',
          search: true },
        { label: '创建时间',
          prop: 'cjsj',
          minWidth: '0px',
          type: 'DateRange',
          cRemarks: '',
          formatter: (row, column) => {
            return this.a.methods.formatterTime(row[column.property || column], 6);
          },
          search: false },
        { label: '收货完成时间',
          prop: 'shwcsjTime',
          minWidth: '0px',
          cRemarks: '',
          search: false },
        ],
        url: '/wmsfailedlibrary/list',
        key: 'id',
        tableColumn: 5,
      },

      dialogInput: {
        kwid: [],
        czr: [],
        row: {},
        size: 'large',
        id: '',
      },
      tableInput: {
        column: [
          { label: '托盘码',
            prop: 'lpn',
            minWidth: '0px',
            cRemarks: '',
            search: true },
          { label: '货品编号',
            prop: 'show_bh',
            minWidth: '0px',
            cRemarks: '',
            search: true },
          { label: '货品名称',
            prop: 'show_mc',
            minWidth: '0px',
            cRemarks: '',
            search: true },
          { label: '上架库位',
            prop: 'show_kwid',
            minWidth: '0px',
            cRemarks: '',
            search: true },
          { label: '批次号',
            prop: 'show_hppc',
            minWidth: '110px',
            cRemarks: '',
            search: true },
          { label: '生产日期',
            prop: 'show_scrq',
            formatter: (row, column) => {
              return this.a.methods.formatterTime(row[column.property || column], 3);
            },
            minWidth: '120px',
            cRemarks: '',
            search: true },
          { label: '收货数量',
            prop: 'sl',
            minWidth: '0px',
            cRemarks: '',
            search: true },
          { label: '上架数量',
            prop: 'sjsl',
            minWidth: '0px',
            cRemarks: '',
            search: true },
          { label: '操作人',
            prop: 'czr',
            minWidth: '0px',
            cRemarks: '',
            search: true },
        ],
        url: '/wmsfailedlibrary/getReceiveList',
        option: {
          asnId: '',
        },
        key: 'kcid',
        tableColumn: 9,
      },

      dialogChoose: {
        row: {},
        index: -1,
        wmsfailedlibrary: '',
      },
      formDialogChoose: __formChoose(),

      dialogOperation: {
        table: '',
        tableInput: {
          mc: '',
        },
      },
      formDialogOperation: __formDialogOperation(),
      dialogOutput: {
        kwid: [],
        czr: [],
        row: {},
        size: 'large',
      },
      tableOutput: {
        column: [
          { label: '托盘码',
            prop: 'lpn',
            minWidth: '0px',
            cRemarks: '',
            search: true },
          { label: '货品编号',
            prop: 'show_bh',
            minWidth: '0px',
            cRemarks: '',
            search: true },
          { label: '货品名称',
            prop: 'show_mc',
            minWidth: '0px',
            cRemarks: '',
            search: true },
          { label: '收货库位',
            prop: 'shkwmc',
            minWidth: '0px',
            cRemarks: '',
            search: true },
          { label: '批次号',
            prop: 'show_hppc',
            minWidth: '110px',
            cRemarks: '',
            search: true },
          { label: '生产日期',
            prop: 'show_scrq',
            formatter: (row, column) => {
              return this.a.methods.formatterTime(row[column.property || column], 3);
            },
            minWidth: '120px',
            cRemarks: '',
            search: true },
          { label: '收货数量',
            prop: 'sl',
            minWidth: '0px',
            cRemarks: '',
            search: true },
          { label: '出库数量',
            prop: 'sjsl',
            minWidth: '0px',
            cRemarks: '',
            search: true },
          { label: '操作人',
            prop: 'czr',
            minWidth: '0px',
            cRemarks: '',
            search: true },
        ],
        url: '/wmsfailedlibrary/getReceiveList',
        option: {
          asnId: '',
        },
        tableColumn: 9,
      },

      dialogChooseOut: {
        row: {},
        index: -1,
        wmsfailedlibrary: '',
      },
      formDialogChooseOut: __formChooseOut(),
      dialogOperationOut: {
        table: '',
        tableOutput: {
          mc: '',
        },
      },
      formDialogOperationOut: __formDialogOperationOut(),
    },
    store: ['USER'],
    transition: 'slide-fade',
    methods: {
      dialogInputInit () {
        this.dialogInput.row = {};
        this.tableClear('tableInput');
      },
      dialogInputOpen (row) {
        console.log('id:' + row.id);
        this.dialogInput.row = row;
        this.dialogInput.row.id = row.id;
        this.tableInput.url = '/wmsfailedlibrary/getReceiveList';
        this.tableInput.option.asnId = row.id;
        this.tableWatch('tableInput');
        this.dialogInput.visible = true;
      },
      tableConfirmDelete (index, row) {
        this.$confirm('您将删除该条明细。', '确认删除？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        })
          .then(() => {
            let table = this.tableInput.data[row.lock];
            table.sl = parseInt(table.sl) + parseInt(row.sl);
            this.tableInput.data.splice(index, 1);
          });
      },
      async dialogInputSave () {
        if (this.tableInput.multipleSelection.length < 1) {
          return this.$alert('请至少选择一条数据！', '提示');
        } else {
          let success = true;
          let result = '';
          this.tableInput.multipleSelection.forEach((item, index) => {
            if (success && !(item.czr && item.sjsl)) {
              success = false;
              result = `请仔细核对 第 ${(index + 1)} 条数据。 货品编号为 ： ${item.show_bh}`;
            }
          });
          if (success) {
            this.$confirm('您将确认上架。', '确认数据准确？', {
              confirmButtonText: '是',
              cancelButtonText: '否',
              type: 'warning',
            })
              .then(async _ => {
                let data = this.tableInput.multipleSelection;
                let step = [];
                data.forEach(item => {
                  let option = Object.assign({}, item);
                  delete option.show_mc;
                  delete option.show_mxzjzt;
                  delete option.sl;
                  delete option.show_scrq;
                  delete option.mxzjzt;
                  delete option.lock;
                  delete option.shkwmc;
                  delete option.lpn;
                  for (let index in option) {
                    if (option.hasOwnProperty(index)) {
                      if (!option[index]) {
                        delete option[index];
                      }
                    }
                  }
                  step.push(option);
                });
                try {
                  await this.post('wmsfailedstorage/add', step);
                  this.tableInput.url = '/wmsfailedlibrary/getReceiveList';
                  this.tableInput.option.asnId = this.dialogInput.row.id;
                  this.tableWatch('tableInput');
                  // this.tableWatch('table');
                  this.dialogInputInit();
                  // this.dialogInput.visible = false;
                } catch (err) {
                  console.log(err);
                }
                this.dialogInput.visible = false;
              })
              .catch(_ => {
              });
          } else {
            return this.$alert(result, '提示！');
          }
        }
      },
      dialogChooseInit () {
        this.dialogChoose.row = {};
        this.dialogChoose.index = -1;
        this.formDialogChoose = {
          ...this.formDialogChoose,
          ...this.ObjectClone(__formChoose()),
        };
        this.resetFields('formDialogChoose');
      },
      async dialogChooseOpen (row, index) {
        row.show_scrq = this.formatterTime(row.show_scrq, 3);
        this.dialogChoose.row = row;
        this.dialogChoose.index = index;
        await AutoPromise([
          async () => {
            if (this.dialogChoose.wmsfailedlibrary.length === 0) {
              this.dialogChoose.wmsfailedlibrary = await this.post('/wmsfailedlibrary/searchKw', {
              });
            }
          },
        ]);
        this.formDialogChoose = {
          ...this.formDialogChoose,
          ...this.ObjectClone(__formChoose(), row),
        };
        this.formDialogChoose.sjsl = parseInt(this.formDialogChoose.sjsl || row.sl);
        this.dialogChoose.visible = true;
      },
      dialogChooseSave () {
        this.VALIDATE('formDialogChoose', async option => {
          this.dialogChoose.row.show_kwid = this.dialogOperation.tableInput.mc;
          for (let index in option) {
            if (option.hasOwnProperty(index)) {
              if (!option[index]) continue;
              this.dialogChoose.row[index] = option[index];
            }
          }
          this.dialogChooseInit();
          this.dialogChoose.visible = false;
        });
      },

      dialogOperationInit () {
        this.dialogOperation.table = '';
        this.dialogOperation.tableInput = {
          mc: '',
        };
        this.formDialogOperation = {
          ...this.formDialogOperation,
          ...this.ObjectClone(__formDialogOperation()),
        };
        this.resetFields('formDialogOperation');
      },
      dialogOperationOpen (table) {
        this.dialogOperation.visible = true;
        this.dialogOperation.table = table;
      },
      dialogOperationSave () {
        let tableRef = this.dialogOperation.table;
        this.VALIDATE('formDialogOperation', option => {
          if (this[tableRef].multipleSelection.length < 1) {
            return this.$alert('您还未选择，请您至少选择一个！', '提示');
          }
          this[tableRef].multipleSelection.forEach(item => {
            item.czr = option.mc;
          });
          this.dialogOperationInit();
          this.dialogOperation.visible = false;
        });
      },
      async dialogChangeKwmc (id) {
        this.dialogChoose.wmsfailedlibrary.forEach(item => {
          if (item.id === id) {
            this.dialogOperation.tableInput.mc = item.mc;
          }
        });
      },

      dialogOutputInit () {
        this.dialogOutput.row = {};
        this.tableClear('tableOutput');
      },
      dialogOutputOpen (row) {
        this.dialogOutput.row = row;
        this.tableOutput.url = '/wmsfailedstorage/getReceiveList';
        this.tableOutput.option.asnId = row.id;
        this.tableWatch('tableOutput');
        this.dialogOutput.visible = true;
      },
      async dialogOutputSave () {
        if (this.tableOutput.multipleSelection.length < 1) {
          return this.$alert('请至少选择一条数据！', '提示');
        } else {
          let success = true;
          let result = '';
          this.tableOutput.multipleSelection.forEach((item, index) => {
            if (success && !(item.czr && item.sjsl)) {
              success = false;
              result = `请仔细核对 第 ${(index + 1)} 条数据。 货品编号为 ： ${item.show_bh}`;
            }
          });
          if (success) {
            this.$confirm('您将确认出库。', '确认数据准确？', {
              confirmButtonText: '是',
              cancelButtonText: '否',
              type: 'warning',
            })
              .then(async _ => {
                let data = this.tableOutput.multipleSelection;
                let step = [];
                data.forEach(item => {
                  let option = Object.assign({}, item);
                  delete option.show_mc;
                  delete option.show_mxzjzt;
                  delete option.show_scrq;
                  delete option.mxzjzt;
                  delete option.lock;
                  delete option.shkwmc;
                  delete option.lpn;
                  delete option.show_hppc;
                  delete option.czr;
                  for (let index in option) {
                    if (option.hasOwnProperty(index)) {
                      if (!option[index]) {
                        delete option[index];
                      }
                    }
                  }
                  step.push(option);
                });
                try {
                  await this.post('/wmsfailedlibrary/add', step);
                  this.tableWatch('tableOutput');
                  this.tableWatch('table');
                  this.dialogOutputInit();
                } catch (err) {
                  console.log(err);
                }
                this.dialogOutput.visible = false;
              })
              .catch(_ => {
              });
          } else {
            return this.$alert(result, '提示！');
          }
        }
      },
      dialogChooseOutInit () {
        this.dialogChooseOut.row = {};
        this.dialogChooseOut.index = -1;
        this.formDialogChooseOut = {
          ...this.formDialogChooseOut,
          ...this.ObjectClone(__formChooseOut()),
        };
        this.resetFields('formDialogChooseOut');
      },
      async dialogChooseOutOpen (row, index) {
        row.show_scrq = this.formatterTime(row.show_scrq, 3);
        this.dialogChooseOut.row = row;
        this.dialogChooseOut.index = index;
        this.formDialogChooseOut = {
          ...this.formDialogChooseOut,
          ...this.ObjectClone(__formChooseOut(), row),
        };
        this.formDialogChooseOut.sjsl = parseInt(this.formDialogChooseOut.sjsl || row.sl);
        this.dialogChooseOut.visible = true;
      },
      dialogChooseOutSave () {
        this.VALIDATE('formDialogChooseOut', async option => {
          this.dialogChooseOut.row.show_kwid = this.dialogOperationOut.tableOutput.mc;
          for (let index in option) {
            if (option.hasOwnProperty(index)) {
              if (!option[index]) continue;
              this.dialogChooseOut.row[index] = option[index];
            }
          }
          this.dialogChooseOutInit();
          this.dialogChooseOut.visible = false;
        });
        /*
        this.VALIDATE('formDialogChooseOut', async option => {
          let sl = parseInt(this.dialogChooseOut.row.sl);
          if (sl !== parseInt(option.sjsl)) {
            let row = Object.assign({}, this.dialogChooseOut.row);
            row.sl = option.sjsl;
            this.tableOutput.data.push({
              ...row,
              ...option,
              lock: this.dialogChooseOut.index,
            });
            console.log();
            this.dialogChooseOut.row.sl = sl - parseInt(option.sjsl);
            this.tableOutput.total++;
          } else {
            for (let index in option) {
              if (option.hasOwnProperty(index)) {
                this.dialogChooseOut.row[index] = option[index];
              }
            }
            this.dialogChooseOut.visible = false;
          }
        });
        */
      },

      dialogOperationOutInit () {
        this.dialogOperationOut.table = '';
        this.dialogOperationOut.tableOutput = {
          mc: '',
        };
        this.formDialogOperationOut = {
          ...this.formDialogOperationOut,
          ...this.ObjectClone(__formDialogOperationOut()),
        };
        this.resetFields('formDialogOperationOut');
      },
      dialogOperationOutOpen (table) {
        this.dialogOperationOut.visible = true;
        this.dialogOperationOut.table = table;
      },
      dialogOperationOutSave () {
        let tableRef = this.dialogOperationOut.table;
        this.VALIDATE('formDialogOperationOut', option => {
          if (this[tableRef].multipleSelection.length < 1) {
            return this.$alert('您还未选择，请您至少选择一个！', '提示');
          }
          this[tableRef].multipleSelection.forEach(item => {
            item.czr = option.mc;
          });
          this.dialogOperationOutInit();
          this.dialogOperationOut.visible = false;
        });
      },
      tableExport (row) {
        let tableRef = 'table';

        let ids = [];
        if (row) {
          ids.push(row.id);
        } else {
          this[tableRef].multipleSelection.forEach(item => {
            ids.push(item.id);
          });
        }
        this.$confirm('您将导出不合格品。', '确认导出？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        })
          .then(async _ => {
            try {
              let option = Object.assign({}, this['autoVue_' + tableRef]);
              await this.p({
                url: '/wmsfailedlibrary/getOutPutList',
                method: 'post',
                responseType: 'blob',
                data: {
                  ids,
                  ...option,
                },
              });
            } catch (err) {
              console.log(err);
            }
          })
          .catch(_ => {
          });
      },
    },
    mounted: function () {
      this.tableWatch('table');
      console.log(this);
    },
  });
</script>
<style scoped lang="scss">
  .box-card {
    margin: 20px;
  }

  .createTimeSpan {
    display: block;
    margin-top: 34px;
  }

  @media screen and (max-width: 800px) {
    .createTimeSpan {
      margin-top: 0;
    }
    .box-card {
      margin: 0;
    }
  }

  .el-select {
    width: 100%;
  }
</style>

<style lang="scss">
  .unqualified{
    width: 88vw;
    float: left;
  }
</style>
